package com.example.ttkl.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.ttkl.Common;
import com.example.ttkl.MainActivity;
import com.example.ttkl.R;
import com.kc.openset.ad.listener.OSETSplashAdLoadListener;
import com.kc.openset.ad.listener.OSETSplashListener;
import com.kc.openset.ad.splash.OSETSplash;
import com.kc.openset.ad.splash.OSETSplashAd;


public class SplashActivity extends AppCompatActivity {
    private static final String TAG = "ss-SplashActivity";

    private FrameLayout fl;
    private Activity activity;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        activity = this;
        fl = findViewById(R.id.fl);

        long startTime = System.currentTimeMillis();
        OSETSplash.getInstance().setContext(this).setPosId(Common.POS_ID_SPLASH).loadAd(new OSETSplashAdLoadListener() {
            @Override
            public void onLoadSuccess(OSETSplashAd osetSplashAd) {
                osetSplashAd.showAd(SplashActivity.this, fl, new OSETSplashListener() {
                    @Override
                    public void onClick() {
                        Log.e(TAG, "onClick");
                    }

                    @Override
                    public void onClose() {
                        Log.e(TAG, "onclose ");
                        startActivity(new Intent(activity, MainActivity.class));
                        finish();
                    }

                    @Override
                    public void onShow() {
                        Log.e(TAG, "onShow " + ( System.currentTimeMillis() - startTime));
                    }

                    @Override
                    public void onError(String s, String s1) {
                        Log.e(TAG, "onError——————code:" + s + "----message:" + s1);
                        startActivity(new Intent(activity, MainActivity.class));
                        finish();
                    }
                });
            }

            @Override
            public void onLoadFail(String s, String s1) {
                startActivity(new Intent(activity, MainActivity.class));
                finish();
            }
        });

    }
}
